// pages/appraisal/appraisal.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    starImg: ['../../images/stars1.png', '../../images/stars1.png', '../../images/stars1.png', '../../images/stars1.png', '../../images/stars1.png'],
    text: ['非常差', '差', '一般', '好', '非常好'],
    evaluate_contant: ['物流评分', '客服评分', '单品评分',],

    stars: [0, 1, 2, 3, 4],
    normalSrc: '../../images/stars1.png',
    selectedSrc: '../../images/stars.png',
    halfSrc: '../../images/stars.png',
    score: 0,
    scores: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    num: 4,//后端给的分数，显示的星星
    one_1: '',//点亮的星星数
    two_1: '',//没有点亮的星星数
    one_2: 0,//点亮的星星数
    two_2: 5,//没有点亮的星星数
    imgloop: [],
    params: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    wx.getStorage({
      key: 'selectOrder',
      success: function (res) {
        that.setData({
          rememberList: res.data.collect
        })

      },
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  loadimg(e) {
    let that = this;
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        // tempFilePath可以作为img标签的src属性显示图片
        const tempFilePaths = res.tempFilePaths
        that.data.imgloop[e.currentTarget.dataset.idx] = tempFilePaths[0]
        that.setData({
          imgloop: that.data.imgloop
        })
        console.log(that.data.imgloop)
      }
    })
  },
  in_xin: function (e) {
    var in_xin = e.currentTarget.dataset.in;
    console.log(e.currentTarget.dataset.in);
    console.log(e.currentTarget);
    var one_2;
    if (in_xin == 'star') {
      one_2 = Number(e.currentTarget.id)
    } else {
      one_2 = Number(e.currentTarget.id) + this.data.one_2
    }
    this.setData({
      one_2: one_2,
      two_2: 5 - one_2
    })
  },
  submit_evaluate: function () {
    console.log('评价得分' + this.data.scores)
  },
  selectLeft: function (e) {
    var score = e.currentTarget.dataset.score
    if (this.data.score == 0.5 && e.currentTarget.dataset.score == 0.5) {
      score = 0;
    }

    this.data.scores[e.currentTarget.dataset.idx] = score,
      this.setData({
        scores: this.data.scores,
        score: score
      })

  },
  selectRight: function (e) {
    var score = e.currentTarget.dataset.score

    this.data.scores[e.currentTarget.dataset.idx] = score,
      this.setData({
        scores: this.data.scores,
        score: score
      })
  },

  ratings: function (e) {
    console.log(e)
    var index = e.currentTarget.dataset.index
    if (e.currentTarget.dataset.index > 0) {
      if (this.data.starImg[index] == '../../images/stars1.png') {
        for (var i = 0; i < index + 1; i++) {
          var starImg = "starImg[" + i + "]"
          this.setData({
            [starImg]: '../../images/stars.png'
          })
        }
      } else if (this.data.starImg[index] == '../../images/stars.png') {
        console.log(index)
        for (var i = index; i < 5; i++) {
          var starImg = "starImg[" + i + "]"
          this.setData({
            [starImg]: '../../images/stars1.png'
          })
        }
      }

    } else {
      if (this.data.starImg[index] == '../../images/stars1.png') {
        var starImg = "starImg[" + i + "]"
        this.setData({
          [starImg]: '../../images/stars.png'
        })
      } else {
        var starImg = "starImg[" + i + "]"
        this.setData({
          [starImg]: '../../images/stars1.png'
        })
      }
    }
  }
})